package app.fugema.shop.main.order.adapter;

import android.view.View;

import com.base.common.model.http.jackSon.JacksonUtils;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.SingleRecyclerAdapter;
import com.base.common.view.adapter.connector.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import app.fugema.shop.R;
import app.fugema.shop.databinding.ItemOrderAfterSaleListViewBinding;
import app.fugema.shop.main.order.model.RefundOrderItem;
import app.fugema.shop.main.order.model.RefundOrdersResult;
import app.fugema.shop.main.order.view.OrderAfterSaleDetailActivity;

public class OrderAfterSaleAdapter extends SingleRecyclerAdapter<RefundOrdersResult.RefundOrder, ItemOrderAfterSaleListViewBinding>
{

    @Override
    public int getLayoutId()
    {
        return R.layout.item_order_after_sale_list_view;
    }

    @Override
    public void onCreateViewHolder(ItemOrderAfterSaleListViewBinding binding, BaseViewHolder viewHolder)
    {
        super.onCreateViewHolder(binding, viewHolder);
        binding.rvRecyclerViewGoods.setAdapter(new RefundGoodsAdapter());
    }

    @Override
    public void onBindViewHolder(ItemOrderAfterSaleListViewBinding binding, int position, BaseViewHolder viewHolder, RefundOrdersResult.RefundOrder bean)
    {
        super.onBindViewHolder(binding, position, viewHolder, bean);

        if(UIUtils.isEmpty( bean.getOrderItems() ))
        {
            RefundOrderItem  item = new RefundOrderItem();
            item.setThumbnailsUrl( bean.getImg() );
            item.setProductName( bean.getProductName()  );
            item.setColorAlias(bean.getColorAlias());
            item.setColor(bean.getColor());
            item.setSizeAlias(bean.getSizeAlias());
            item.setSize(bean.getSize());
            item.setVersionAlias(bean.getVersionAlias());
            item.setVersion(bean.getVersion());
            List<RefundOrderItem>  itemList = new ArrayList<>();
            itemList.add( item );
            bean.setOrderItems(itemList);
        }

        if (binding.rvRecyclerViewGoods.getAdapter() instanceof RefundGoodsAdapter)
        {
            RefundGoodsAdapter refundAdaoter = (RefundGoodsAdapter) binding.rvRecyclerViewGoods.getAdapter();
            refundAdaoter.setDataList( bean.getOrderItems() );
        }
    }

    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, RefundOrdersResult.RefundOrder bean)
    {
        super.onItemClick(view, adapter, onclickType, position, bean);
        OrderAfterSaleDetailActivity.start(view.getContext(), bean.getId() , bean.getShopName(), JacksonUtils.transBean2Json( bean.getOrderItems() ));

    }
}
